// 分析报告导出
import * as htmlToImage from "html-to-image";
import { chartImgBase64 } from "@/utils/utils";
export default {
  methods: {
    analysisExport() {
      let _this = this;
      _this.$nextTick(() => {
        _this.createImage();
      });
    },
    createImage() {
      let _this = this;
      const query = _this.$route.query;
      if (!query.export) {
        return;
      }

      if (
        _this.routerName == "technologyFrontier" ||
        _this.routerName == "technologyMaturity"
      ) {
        setTimeout(() => {
          const chartImg = chartImgBase64(_this.dom) || "";
          _this.updateAnalysisCacheData(chartImg, query);
        }, 10000);
      } else {
        let idDom = document.getElementById("technologyTopicTrends");
        setTimeout(() => {
          htmlToImage.toPng(idDom).then(function(dataurl) {
            _this.updateAnalysisCacheData(dataurl, query);
          });
        }, 10000);
      }
    },
    updateAnalysisCacheData(dataurl, query) {
      let list = [];
      const routerName = this.routerName;
      switch (routerName) {
        case "technologyFrontier":
          list = this.termsChartData;
          break;
        case "technologyMaturity":
          list = this.chartData;
          break;
        case "technologyTopicTrends":
          list = this.termsChartData;
          break;
        case "patentRoadmap":
          list = this.patentData;
          break;
      }
      let param = {
        postResult: JSON.stringify(list),
        postJson: "",
        echartsImg: dataurl,
        tableImg: "",
        historyid: parseInt(query.historyId),
        code: routerName,
      };
      // console.log("param11111", param);
      this.$post(this.$Url.analysis.updateAnalysisCacheData, param).then(
        (res) => {
          // console.log("------", res.data);
        }
      );
    },
  },
};
